import { useLocation, useParams } from 'react-router-dom';

/**
 * @author liyuan
 * @date 07-18 14:25:12
 * @desc 路由hook
 */
export const useRouter = () => {
  const location = useLocation();
  const params = useParams();

  /**
   * @author liyuan
   * @date 07-18 14:10:45
   * @desc 获取路由参数，包含路由参数和查询参数
   */
  const getUrlParams = () => {
    const searchParams = new URLSearchParams(location.search);
    return {
      ...params,
      search: Object.fromEntries(searchParams),
    };
  };
  return {
    getUrlParams,
  };
};
